package com.zhicheng.mapper;

import com.zhicheng.pojo.Category;
import com.zhicheng.pojo.CategoryTwo;
import com.zhicheng.pojo.vo.CategoryTwoVO;
import com.zhicheng.pojo.vo.CategoryVO;
import com.zhicheng.pojo.vo.GoodVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {

    @Select("select * from category where id = #{id}")
    CategoryVO selectCategoryById(Long id);

    @Select("select * from category_two where category_id = #{id}")
    List<CategoryVO> selectCategoryTwoByCategoryId(Long id);

    @Select("select * from goods where category_id = #{categoryId} and status = 1")
    List<GoodVO> selectGoodByCategoryId(Long categoryId);

    @Select("select * from goods where parent_id = #{parentId} and status = 1")
    List<GoodVO> selectGoodByParentId(Long parentId);

    @Select("select * from category_two where id = #{id} ;")
    CategoryTwoVO selectCategoryTwoById(Long id);

    @Select("select * from goods where name like CONCAT('%',#{name},'%')")
    List<GoodVO> getByGoodName(String name);

    @Select("select * from category_two")
    List<CategoryTwo> getSubCategory();

    @Select("select * from category")
    List<Category> getCategoryPage();

    @Insert("insert into category (`name`, category_pic, create_time, update_time) " +
            "VALUES(#{name},#{categoryPic},#{createTime},#{updateTime}) ")
    void add(Category category);

    void updateCategory(Category category);

    @Delete("delete from category where id = #{id};")
    void deleteCategory(Long id);

    @Insert("insert into category_two(`name`, category_pic, category_id, parent_name, create_time, update_time) " +
            "VALUES(#{name},#{categoryPic},#{categoryId},#{parentName},#{createTime},#{updateTime}) ")
    void addSubCategory(CategoryTwo categoryTwo);

    void updateSubCategory(CategoryTwo categoryTwo);

    @Delete("delete from category_two where id = #{id};")
    void deleteSubCategory(Long id);

    List<CategoryTwo> getSubCategoryQuery(Long categoryId);
}
